How to send Notes to the Customer from a Custom Page using an Action button in Dynamics NAV

Introduction:

The requirement is explained in the Scenario below:

Scenario:

A Custom page called Collection Module-Per User has details of Customers Transaction. This Collection Per User page is a List page. The User will select the line and Click on Notes. Notes will written and saved. The user will Click on the Action button Send Notes to Customer.The Notes from this Custom page should be sent to standard page Customer (Page 18)

Intro 1

Notes in Microsoft Dynamics NAV

Notes are like reminders or notification which is ideally used for Customers,Vendors or Items.  Notes are saved in binary format in a field Note of Blob data type in the table Record Link  (2000000068)

Read notes : The “Record ID” of the record using Record Reference is used to filter the Record Link table and convert the data stored in the Note field in Record Link table to text.

Write Notes: The “Record ID” of the record using Record Reference is used to filter the Record Link table and convert the text to bytes and store in the Note field

Pre-requisites:

Microsoft Dynamics NAV 2017

Steps:

Functionality:

  1. Select the line in the Custom page and click on Notes. Type in your Notes and Save it.

typenotes

2. Click on Send Notes to Customer.

savenotes

3. Open the Customer page and filter the Customer No to which Notes are sent and Open Notes.

note from customer

Customization:

  1. Create an Action button Send Notes to Customer and create global variables as below image:

globals

2. The Custom Table has primary key as No. so first GET the primary key and assign Customer No. to a variable Rec_CustNo

ReadText:

Rec_CF_CollectionModuleTempTable.GET(No);
 Rec_CustNo:=Rec_CF_CollectionModuleTempTable.CustNo;

Set the Recfilter and use the Recorf reference to GETTABLE.

Rec_CF_CollectionModuleTempTable.SETRECFILTER;
CLEAR(RecRef);
RecRef.GETTABLE(Rec_CF_CollectionModuleTempTable);
RecRef.FINDFIRST;

3. SETRANGE with the Record Link’s Table Record ID and Record referrence RECORDID

4. Convert the blob field into text by using InStream and Use a BigText variable to read the Stream.

RecordLink.RESET;
RecordLink.SETCURRENTKEY("Record ID");
RecordLink.SETRANGE("Record ID",RecRef.RECORDID);
IF RecordLink.FINDFIRST THEN BEGIN
 RecordLink.CALCFIELDS(Note);
 IF RecordLink.Note.HASVALUE THEN BEGIN
 CLEAR(NoteText);
 RecordLink.Note.CREATEINSTREAM(Stream);
 NoteText.READ(Stream);
 NoteText.GETSUBTEXT(NoteText,2);
 END;
 END;

Write Text:

1. GET the Customer No. of the Cuatomer Table and Use Record refernce to GETTABLE Customer. Use SetText function to write the text to bytes and store it in Note field in Record Link

Customer.GET(Rec_CustNo);
 RecRef.GETTABLE(Customer);
 RecordLink.INIT;
 RecordLink."Link ID":=0;
 RecordLink."Record ID":=RecRef.RECORDID;
 RecordLink.URL1:=GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,PAGE::"Customer Card");
 RecordLink.Type:=RecordLink.Type::Note;
 RecordLink.Created:=CURRENTDATETIME;
 RecordLink."User ID":=USERID;
 RecordLink.Company:=COMPANYNAME;
 RecordLink.Notify:=TRUE;
 SetText(NoteText,RecordLink);
 RecordLink.INSERT;

The Complete Code :

Send Notes to Customer - OnAction()
 Rec_CF_CollectionModuleTempTable.GET(No);
 Rec_CustNo:=Rec_CF_CollectionModuleTempTable.CustNo;
 //MESSAGE('%1 no',Rec_CF_CollectionModuleTempTable.CustNo);

Rec_CF_CollectionModuleTempTable.SETRECFILTER;
CLEAR(RecRef);
RecRef.GETTABLE(Rec_CF_CollectionModuleTempTable);
RecRef.FINDFIRST;

RecordLink.RESET;
RecordLink.SETCURRENTKEY("Record ID");
RecordLink.SETRANGE("Record ID",RecRef.RECORDID);
IF RecordLink.FINDFIRST THEN BEGIN
 REPEAT
 RecordLink.CALCFIELDS(Note);
 IF RecordLink.Note.HASVALUE THEN BEGIN
 CLEAR(NoteText);
 RecordLink.Note.CREATEINSTREAM(Stream);
 NoteText.READ(Stream);
 NoteText.GETSUBTEXT(NoteText,2);
 MESSAGE(FORMAT(NoteText));
 END;
 UNTIL RecordLink.NEXT=0;
 END;
 
 
 Customer.GET(Rec_CustNo);
 RecRef.GETTABLE(Customer);
 RecordLink.INIT;
 RecordLink."Link ID":=0;
 RecordLink."Record ID":=RecRef.RECORDID;
 RecordLink.URL1:=GETURL(CLIENTTYPE::Windows,COMPANYNAME,OBJECTTYPE::Page,PAGE::"Customer Card");
 RecordLink.Type:=RecordLink.Type::Note;
 RecordLink.Created:=CURRENTDATETIME;
 RecordLink."User ID":=USERID;
 RecordLink.Company:=COMPANYNAME;
 RecordLink.Notify:=TRUE;
 SetText(NoteText,RecordLink);
 RecordLink.INSERT;

PROCEDURE SetText@1000000002(NoteText@1000000000 : BigText;VAR RecordLink@1000000001 : Record 2000000068);
 VAR
 s@1000000002 : BigText;
 Ostr@1000000003 : OutStream;
 lf@1000000004 : Text;
 c1@1000000005 : Char;
 c2@1000000006 : Char;
 x@1000000007 : Integer;
 y@1000000008 : Integer;
 i@1000000009 : Integer;
 SystemUTF8Encoder@1000000011 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.UTF8Encoding";
 SystemByteArray@1000000010 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";
 BEGIN
 s := NoteText;
 SystemUTF8Encoder := SystemUTF8Encoder.UTF8Encoding;
 SystemByteArray := SystemUTF8Encoder.GetBytes(s);

RecordLink.Note.CREATEOUTSTREAM(Ostr);
 x := SystemByteArray.Length DIV 128;
 IF x > 1 THEN
 y := SystemByteArray.Length - 128 * (x - 1)
 ELSE
 y := SystemByteArray.Length;
 c1 := y;
 Ostr.WRITE(c1);
 IF x > 0 THEN BEGIN
 c2 := x;
 Ostr.WRITE(c2);
 END;
 FOR i := 0 TO SystemByteArray.Length - 1 DO BEGIN
 c1 := SystemByteArray.GetValue(i);
 Ostr.WRITE(c1);
 END;
 END;

LOCAL PROCEDURE HtmlEncode@20(InText@1000 : Text[1024]) : Text[1024];
 VAR
 SystemWebHttpUtility@1001 : DotNet "'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.System.Web.HttpUtility";
 BEGIN
 SystemWebHttpUtility := SystemWebHttpUtility.HttpUtility;
 EXIT(SystemWebHttpUtility.HtmlEncode(InText));
 END;

 

3 thoughts on “How to send Notes to the Customer from a Custom Page using an Action button in Dynamics NAV

  1. Very very very and very interesting..
    ..but in my NAV installation I can’t find:
    SystemUTF8Encoder@1000000011 : DotNet “‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.Text.UTF8Encoding”;
    and
    SystemByteArray@1000000010 : DotNet “‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.System.Array”;
    maybe because I work with NAV2016 ?
    Thank You in advance
    Alessandro

    Like

Leave a comment